package com.dd.stack.rpc.dubbo.consumer.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;

/**
 * @Author liuxianmeng
 * @CreateTime 2024/9/20 23:31
 * @Description API配置
 */
@Configuration
@EnableSwagger2WebMvc
public class OpenAPIConfig {

    @Bean
    public Docket docket(Environment environment){

        /**
         * 一个用来作为Springfox框架的主要接口的构建器 提供合理的默认值和方便的配置方法
         */
        return new Docket(DocumentationType.SWAGGER_2)
                // 配置apiInfo信息
                .apiInfo(apiInfo())
                // enable是否启动了Swagger 如果是False 则Swagger不能在浏览器中访问
                .enable(true)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.dd.stack.rpc.dubbo.consumer.controller"))
                //.paths(PathSelectors.ant("/qi/**"))
                .build();
    }
    // 配置Swagger信息
    private ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("liuxianmeng", "https://blog.bigbigmeng.online", "2751187368@qq.com");
        return new ApiInfo("Dubbo远程过程调用 服务消费方",
                "Api Documentation -> Dubbo远程过程调用 服务消费方",
                "v1.0", "urn:tos",
                contact, "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}

